package de.fhaugsburg.games.boardgames;

import java.util.ArrayList;
import java.util.List;
/**
 * A CircularList use a ArrayList from the Collection api, to put an element to the list.
 * To return the next or previous element from the list. for this method the class use the
 * int attribute current.
 * @author r4smus
 *
 * @param <T>
 */
public class CircularList<T> {
	
	private List<T> list = new ArrayList<T>();
	private int current = 0;
/**
 * add a element to the list.	
 * @param t
 */
	public void add(T t	){
		list.add(t);
	}
/**
 * 
 * @return the next element from the list, if we are at the end of the list, the first element is returned.
 */
	public T next(){
		if(current == list.size()-1){
			current = 0;
			return list.get(current);
		}
		return list.get(++current);
	}
/**
 * clear the list and set the current attribute to 0.
 */
	public void reset(){
		list.clear();
		current = 0;
	}
/**
 * 
 * @return the previous element from the list, if we are at the beginning of the list, the last element in the list is returned.
 */
	public T prev(){
		if(current == 0){
			current = list.size()-1;
			return list.get(current);
		}		
		return list.get(--current);
	}
/**
 * 
 * @return a List object with all elements.
 */
	public List<T> getAll(){
		return list;
	}
	

}
